package cn.bdqn.mh.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration  //配置类
@EnableSwagger2 //启用swagger2
public class Swagger2Config {
    @Bean
    public ApiInfo apiInfo(){
        //这里配置了api的基本提示信息 4个要素
        return new ApiInfoBuilder().title(("springboot中使用swagger生成的Restful MicroHouseAPI帮助信息"))
                .description(("更新的信息，请浏览我司网站http://www.alibaba.com"))
                .termsOfServiceUrl("http://www.alibaba.com")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()//返回builder实例，控制哪些方法是暴露给swagger展示
                //扫描哪些包的控制器需要生成
                .apis(RequestHandlerSelectors.basePackage("cn.bdqn.mh.controller.api"))
                .paths(PathSelectors.any())
                .build();
    }

}
